import React from "react";

export default [
  {
    title: "序号",
    dataIndex: "id",
    width: 50,
    render: (a, b, c) => <span>{pageSize * (pageNum - 1) + c + 1}</span>
  },
  {
    title: "消息模版编码",
    dataIndex: "templateCode"
  },
  {
    title: "消息模版名称",
    dataIndex: "templateName"
  },
  {
    title: "消息模版标题",
    dataIndex: "templateTitle"
  },
  {
    title: "来源",
    dataIndex: "creator",
    render: text => <span>{text || "--"}创建</span>
  },
  {
    title: "状态",
    dataIndex: "isEnabled",
    render: text => {
      let res;
      switch (text) {
        case "Y":
          res = <Badge status="success" text="启用" />;
          break;
        case "N":
          res = <Badge status="default" text="停用" />;
          break;
        default:
          res = "";
      }
      return res;
    }
  },
  {
    title: "备注",
    ellipsis: true,
    dataIndex: "description"
  },
  {
    title: "预览模板",
    dataIndex: "preview",
    // fixed: "right",
    render: (text, record) => <a onClick={() => handlePreview(record)}>预览</a>
  },
  {
    title: "操作",
    dataIndex: "handle",
    width: 160,
    fixed: "right",
    render: (text, record) => {
      const isDisable = record.isEnabled === "Y";
      const offLineTitle =
        record.isEnabled === "Y" ? "确定停用模板吗" : "确定启用模板吗";
      return (
        <div>
          <a
            disabled={isDisable}
            onClick={() =>
              history.push(
                `/messageCenter/templateManager/add?templateId=${record.templateId}`
              )
            }
          >
            编辑
          </a>
          <Divider type="vertical" />
          <Popconfirm
            title="确定删除这一模板吗"
            onConfirm={() => handleDelete(record.templateId)}
          >
            <a disabled={isDisable}>删除</a>
          </Popconfirm>
          <Divider type="vertical" />
          <Popconfirm
            title={offLineTitle}
            onConfirm={() => handleCommit(record)}
          >
            {record.isEnabled === "Y" ? (
              <a>停用</a>
            ) : (
              <a disabled={isDisable}>启用</a>
            )}
          </Popconfirm>
        </div>
      );
    }
  }
];
